package com.tool.emulator.common;

/**
 * AutoDevice.java @author tl 2011-6-17
 */
public abstract class AutoDevice extends VirtualDevice {
	public static final long MIN_FREQ = 1;

	//只是取值范围，实际模拟不了那么快。
	public static final long MAX_FREQ = 10L * 1000L * 1000L * 1000L;
	private final long raw_freq;
	protected int current_cycles;
	protected transient volatile boolean running;
	transient long freq;
	transient long cycles;
	private transient volatile Inspector inspector;

	protected AutoDevice(String name, long freq) {
		super(name);
		this.setFreq(freq);
		this.raw_freq = freq;
	}

	public long getRawFreq() {
		return this.raw_freq;
	}

	public Inspector getInspector() {
		return this.inspector;
	}

	public void setInspector(Inspector inspector) {
		this.inspector = inspector;
	}

	public boolean isRunning() {
		return this.running;
	}

	public long getFreq() {
		return this.freq;
	}

	public void setFreq(long freq) {
		if (freq < MIN_FREQ || freq > MAX_FREQ)
			throw new IllegalArgumentException("freq must between " + MIN_FREQ + " and " + MAX_FREQ);
		this.freq = freq;
	}

	public long getCycles() {
		return this.cycles + current_cycles;
	}

	protected abstract boolean deviceStep();

}
